<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>改变背景颜色</title>
</head>
<body>
    <button id="red">红色</button>
    <button id="green">绿色</button>
    <button id="blue">蓝色</button>
</body>
</html>
<script>
    var red=document.getElementById("red");
    red.onclick=function(){
        document.body.style.backgroundColor="red"
    }
    var green=document.getElementById("green");
    green.onclick=function(){
        document.body.style.backgroundColor="green"
    }
    var blue=document.getElementById("blue");
    blue.onclick=function(){
        document.body.style.backgroundColor="blue"
    }
</script>